<?php


namespace app\hotel\controller;

use app\BaseController;
use app\hotel\validate\ReservationValidate;
use app\model\Order;
use app\service\ReservationService;
use think\App;

class ReservationController extends BaseController
{
    private $ReservationService;

    public function __construct(App $app)
    {
        $this->ReservationService = new ReservationService();
        parent::__construct($app);
    }

    public function getReservation(Order $order){
        return $this->returnJson($this->ReservationService->gerReservation($order->id));
    }

    public function getReservationAll(){
        $user_id = $this->request->user->id;
        return $this->returnJson($this->ReservationService->gerReservationAll($user_id));
    }

    public function getUnsubscribeAll(){
        $user_id = $this->request->user->id;
        return $this->returnJson($this->ReservationService->gerReservationAll($user_id , true));
    }

    public function reservation(){
        $param = $this->request->param(['room_id' , 'start_time' , 'end_time' , 'deposit' , 'price']);
        validate(ReservationValidate::class)->scene('Reservation')->check($param);
        $user_id = $this->request->user->id;
        return $this->returnJson($this->ReservationService->reservation($user_id , $param['room_id'] , $param['deposit'] , $param['price'] , $param['start_time'] , $param['end_time']));
    }

    public function unsubscribe(Order $order){
        $this->ReservationService->unsubscribe($order->id);
        return $this->returnJson();
    }
}